From: Colin Walters Date: Tue, 29 Apr 2025 22:31:16 +0000 (-0400) Subject: bin/set-origin: Don't crash if origin has no refspec X-Git-Tag: archive/raspbian/2025.7-2+rpi1^2^2~6^2~4^2~36^2~5 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:///%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:/?a=commitdiff_plain;h=832f3d7820388da1d73a3f4cc44ff9fbbe9b3bb1;p=ostree.git bin/set-origin: Don't crash if origin has no refspec e.g. if it's using a container instead. Signed-off-by: Colin Walters --- diff --git a/src/ostree/ot-admin-builtin-set-origin.c b/src/ostree/ot-admin-builtin-set-origin.c index 1bb0d098..d014fb00 100644 --- a/src/ostree/ot-admin-builtin-set-origin.c +++ b/src/ostree/ot-admin-builtin-set-origin.c @@ -111,12 +111,18 @@ ot_admin_builtin_set_origin (int argc, char **argv, OstreeCommandInvocation *inv g_autofree char *origin_remote = NULL; g_autofree char *origin_ref = NULL; - if (!ostree_parse_refspec (origin_refspec, &origin_remote, &origin_ref, error)) - return FALSE; + if (origin_refspec != NULL) + { + if (!ostree_parse_refspec (origin_refspec, &origin_remote, &origin_ref, error)) + return FALSE; + } + else if (branch == NULL) + return glnx_throw (error, "No host refspec found, branch is required"); + const char *target_branch = branch ?: origin_ref; + g_assert (target_branch); { - g_autofree char *new_refspec - = g_strconcat (remotename, ":", branch ? branch : origin_ref, NULL); + g_autofree char *new_refspec = g_strconcat (remotename, ":", target_branch, NULL); g_autoptr (GKeyFile) new_origin = NULL; new_origin = ostree_sysroot_origin_new_from_refspec (sysroot, new_refspec);